import pymysql


class DatabaseManager:
    def __init__(self):
        self.conn = pymysql.connect(host="localhost", user='root', password='123456', port=3306, db='spyder')
        self.cursor = self.conn.cursor()

    def execute(self, sql):
        self.cursor.execute(sql)
        rowcount = self.cursor.rowcount
        print("造成了{}条数据变动".format(rowcount))

    def select(self, sql):
        self.cursor.execute(sql)
        fetchall = self.cursor.fetchall()
        for row in fetchall:
            print(row)

    def commit_and_close(self):
        self.conn.commit()
        self.conn.close()

    def close(self):
        self.cursor.close()
        self.conn.close()